
<template>
  <BasicLayout>
    <template #wrapper>
      <el-card class="box-card">
        <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
          <el-form-item label="姓名" prop="name"><el-input
            v-model="queryParams.name"
            placeholder="请输入姓名"
            clearable
            maxlength="11"
            size="small"
            @keyup.enter.native="handleQuery"
          />
          </el-form-item>
          <el-form-item label="手机号" prop="phone"><el-input
            v-model="queryParams.phone"
            placeholder="请输入手机号"
            clearable
            maxlength="11"
            size="small"
            @keyup.enter.native="handleQuery"
          />
          </el-form-item>
          <el-form-item label="性别" prop="sex"><el-select
            v-model="queryParams.sex"
            placeholder="性别"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in sexOptions"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
          </el-form-item>
          <el-form-item label="评级" prop="level"><el-input
            v-model="queryParams.level"
            placeholder="请输入评级"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
          </el-form-item>
          <el-form-item label="备注信息" prop="note"><el-input
            v-model="queryParams.note"
            placeholder="请输入备注信息"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
          </el-form-item>

          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              v-permisaction="['hunter:htTalent:add']"
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
            >新增
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              v-permisaction="['hunter:htTalent:edit']"
              type="success"
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
            >修改
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              v-permisaction="['hunter:htTalent:remove']"
              type="danger"
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
            >删除
            </el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              v-permisaction="['hunter:htTalent:add']"
              type="danger"
              icon="el-icon-plus"
              size="mini"
              @click="handleImport"
            >导入
            </el-button>
          </el-col>
        </el-row>

        <el-table v-loading="loading" :data="htTalentList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" /><el-table-column
            label="姓名"
            align="center"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <el-button
                v-permisaction="['hunter:htTalent:edit']"
                type="text"
                size="small"
                @click="handleUpdate(scope.row)"
              >{{ scope.row.name }}
              </el-button>
            </template>
          </el-table-column>
          <el-table-column
            label="手机号"
            align="center"
            prop="phone"
            :show-overflow-tooltip="true"
          /><el-table-column
            label="性别"
            align="center"
            prop="sex"
            :formatter="sexFormat"
            width="100"
          >
            <template slot-scope="scope">
              {{ sexFormat(scope.row) }}
            </template>
          </el-table-column><el-table-column
            label="评级"
            align="center"
            prop="level"
            :show-overflow-tooltip="true"
          /><el-table-column
            label="备注信息"
            align="center"
            prop="note"
            :show-overflow-tooltip="true"
          />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                slot="reference"
                v-permisaction="['hunter:htTalent:edit']"
                size="mini"
                type="text"
                icon="el-icon-chat-dot-square"
                @click="handleDelivery(scope.row)"
              >交付
              </el-button>
              <el-button
                slot="reference"
                v-permisaction="['hunter:htTalent:edit']"
                size="mini"
                type="text"
                icon="el-icon-chat-dot-square"
                @click="handleView(scope.row)"
              >沟通
              </el-button>
              <el-popconfirm
                class="delete-popconfirm"
                title="确认要删除吗?"
                confirm-button-text="删除"
                @confirm="handleDelete(scope.row)"
              >
                <el-button
                  slot="reference"
                  v-permisaction="['hunter:htTalent:remove']"
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                >删除
                </el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageIndex"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

        <talent-info
          v-if="formOpen || uploadOpen"
          :title="title"
          :form-open="formOpen"
          :upload-open="uploadOpen"
          :form="form"
          :sex-options="sexOptions"
          :on-close="handleClose"
        />
        <talent-view
          v-if="contractOpen"
          :contract-open="contractOpen"
          :title="title"
          :form="form"
          :sex-options="sexOptions"
          :on-close="handleClose"
        />
        <delivery-info
          v-if="deliverOpen"
          :deliver-open="deliverOpen"
          :title="title"
          :deliver-talent-id="deliverTalentId"
          :on-close="handleClose"
        />
      </el-card>
    </template>
  </BasicLayout>
</template>

<script>
import { delHtTalent, getHtTalent, listHtTalent } from '@/api/hunter/ht-talent'
import TalentInfo from '../components/TalentInfo'
import TalentView from '../components/TalentView'
import DeliveryInfo from '../components/DeliverInfo'
export default {
  name: 'HtTalent',
  components: {
    TalentInfo,
    TalentView,
    DeliveryInfo
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      formOpen: false,
      uploadOpen: false,
      contractOpen: false,
      isEdit: false,
      // 类型数据字典
      typeOptions: [],
      htTalentList: [],
      sexOptions: [],
      deliverTalentId: undefined,
      deliverOpen: false,
      // 查询参数
      queryParams: {
        pageIndex: 1,
        pageSize: 10,
        name: undefined,
        phone: undefined,
        sex: undefined,
        level: undefined,
        note: undefined

      },
      // 表单参数
      form: {
      },
      // 表单校验
      rules: { name: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
        phone: [{ required: true, message: '手机号不能为空', trigger: 'blur' }],
        sex: [{ required: true, message: '性别不能为空', trigger: 'blur' }],
        level: [{ required: true, message: '评级不能为空', trigger: 'blur' }],
        note: [{ required: true, message: '备注信息不能为空', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.getList()
    this.getDicts('sys_user_sex').then(response => {
      this.sexOptions = response.data
    })
  },
  methods: {
    /** 查询参数列表 */
    getList() {
      this.loading = true
      listHtTalent(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.htTalentList = response.data.list
        this.total = response.data.count
        this.loading = false
      }
      )
    },
    handleClose() {
      this.uploadOpen = false
      this.formOpen = false
      this.contractOpen = false
      this.deliverOpen = false
      this.getList()
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        name: undefined,
        phone: undefined,
        sex: undefined,
        email: undefined,
        status: undefined,
        level: undefined,
        note: undefined
      }
      this.resetForm('form')
    },
    getImgList: function() {
      this.form[this.fileIndex] = this.$refs['fileChoose'].resultList[0].fullUrl
    },
    fileClose: function() {
      this.fileOpen = false
    },
    sexFormat(row) {
      return this.selectDictLabel(this.sexOptions, row.sex)
    },
    // 关系
    // 文件
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageIndex = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.formOpen = true
      this.title = '添加人才'
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id =
                row.id || this.ids
      getHtTalent(id).then(response => {
        this.form = response.data
        this.formOpen = true
        this.title = '修改人才'
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      var Ids = (row.id && [row.id]) || this.ids

      this.$confirm('是否确认删除编号为"' + Ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return delHtTalent({ 'ids': Ids })
      }).then((response) => {
        if (response.code === 200) {
          this.msgSuccess(response.msg)
          this.open = false
          this.getList()
        } else {
          this.msgError(response.msg)
        }
      }).catch(function() {
      })
    },
    /** 导入按钮操作 */
    handleImport() {
      this.title = '导入人才'
      this.uploadOpen = true
    },
    handleView(row) {
      var that = this
      getHtTalent(row.id).then(response => {
        that.reset()
        that.form = response.data
        that.contractOpen = true
        that.title = '沟通人才'
      })
    },
    handleDelivery(row) {
      this.deliverTalentId = row.id
      this.deliverOpen = true
    }
  }
}
</script>
